// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
// import dayjs from 'dayjs'
import * as rem from './rem'
import * as filters from './utils/filters'
import {FastClick} from './fastclick'
import config from './config'
import utils from './utils'
// import ScatterJS from 'scatterjs-core'
import ScatterJS from 'scatter-js/dist/scatter.esm'
import VueClipboards from 'vue-clipboard2'
import VueResource from 'vue-resource'
/* eslint-disable no-unused-vars */
import element from '@/utils/element'
import i18n from '@/utils/i18n'

require('./assets/style/global.css')
require('./assets/style/iconfont.css')
require('./assets/style/css.css')
require('./assets/style/media.css')
require('./assets/style/swiper.min.css')

const EOS = require('eosjs')
const Interval = require('./interval')
rem.init()
Vue.config.productionTip = false
Vue.prototype.$eosjs = EOS
// Vue.prototype.$dayjs = dayjs
Vue.prototype.$scatterJs = ScatterJS
Vue.prototype.$config = config
Vue.prototype.$utils = utils
Vue.prototype.$isMobile = document.body.clientWidth >= 1200 ? false : true // eslint-disable-line
Vue.use(VueClipboards)
Vue.use(VueResource)
Object.keys(filters).forEach(k => Vue.filter(k, filters[k]))
window.ScatterJS = null
// 去除手机的300毫秒点击延迟
FastClick.attach(document.body)

/* eslint-disable no-new */
function getLocalLang () {
  if (localStorage) {
    let lang = localStorage.getItem('lang')
    if (lang) {
      store.dispatch('setLang', lang)
    }
    // return false
  } else if (window.navigator) {
    if (navigator.language === 'en') {
      store.dispatch('setLang', 'en')
    } else {
      store.dispatch('setLang', 'zh')
    }
  }
}
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App),
  mounted () {
    getLocalLang()
    var inviter = this.$utils.GetQueryString('ref')
    if (inviter) {
      window.localStorage.setItem('rab_ivt', inviter)
    } else {
      window.localStorage.setItem('rab_ivt', '')
    }
    const that = this
    window.onresize = () => {
      var screenWidth = document.body.clientWidth
      var isMobile = store.getters.getIsMobile
      if (screenWidth >= 1050 && isMobile === true) {
        store.commit('SETISMOBILE', false)
      }
      if (screenWidth < 1050 && isMobile === false) {
        store.commit('SETISMOBILE', true)
      }
    }
  },
  watch: {
    '$store.state.lang' (newVal, oldVal) {
      this.$i18n.locale = newVal
    }
  }
})
